from requestMethod.mallHomeApi import Req_api
from common.b_yamlOperate import YamlRead,pathConf
from jsonschema import validate

class strut_mallHome():

    def __init__(self):
        pass

    def SpuDetailSruct(self):
        """
        验证商品详情数据结构
        :uri : /front/p/newGoodsSpu/newGoodsSpuDetail
        :author 露驿星程
        """
        reqC = Req_api()
        res = reqC.newGoodsSpuDetail()
        json_data = res.json()
        my_schema1 = YamlRead(pathConf.get_userFilePath("data/i_checkPoint/dataStruct.yaml")).getdata()['newGoodsSpuDetail']
        validate(instance=json_data, schema=my_schema1)  # 验证

    def homePageSruct(self):
        """
        验证首页主接口数据结构
        :uri : /front/p/mallHome/main
        :author 露驿星程
        """
        reqC = Req_api()
        res = reqC.homePage()
        json_data = res.json()
        my_schema1 = YamlRead(pathConf.get_userFilePath("data/i_checkPoint/dataStruct.yaml")).getdata()['homePage']
        validate(instance=json_data, schema=my_schema1)

    def topProductsStruct(self):
        """
        验证商城首页平台推荐接口数据结构
        :uri : /front/p/mallHome/topProducts
        :author 露驿星程
        """
        reqC = Req_api()
        res = reqC.topProducts()
        json_data = res.json()
        # print(json_data)
        my_schema = YamlRead(pathConf.get_userFilePath("data/i_checkPoint/dataStruct.yaml")).getdata()['topProducts']
        validate(instance=json_data, schema=my_schema)

    def weeklyProductsStruct(self):
        """
        验证本周上新接口数据结构
        :uri : /front/p/mallHome/weeklyProducts
        :author 露驿星程
        """
        reqC = Req_api()
        res = reqC.weeklyProducts()
        json_data = res.json()
        # print(json_data)
        my_schema = YamlRead(pathConf.get_userFilePath("data/i_checkPoint/dataStruct.yaml")).getdata()['weeklyProducts']
        validate(instance=json_data, schema=my_schema)


if __name__ == "__main__":
    pass
    VerifyC = strut_mallHome()
    VerifyC.weeklyProductsStruct()